package com.zipking.cloud.springbootmybatis.util.excel;

import com.alibaba.excel.EasyExcel;
import com.alibaba.excel.ExcelWriter;

import java.util.ArrayList;
import java.util.List;

public class ExcelExportDemo {
    public static void main(String[] args) {

// 输出文件路径
        String filePath = "D:/demo.xlsx";
        // Sheet名称
        String sheetName = "Sheet1";
        // 写入数据的Sheet编号
        int writeSheet = 0;

        // 创建ExcelWriter对象
        //ExcelWriter excelWriter = EasyExcel.write(filePath, DemoData.class).sheet(sheetName).build();

        // 定义每页数据量
        int pageSize = 10000;
        // 定义数据总量
        int totalCount = 100000;

        // 定义分页查询器
     /*   PageQuery<DemoData> pageQuery = new PageQuery<>(pageNum -> {
            // 模拟从数据库中查询指定页码的数据
            List<DemoData> data = new ArrayList<>();
            int startIndex = (pageNum - 1) * pageSize;
            int endIndex = Math.min(startIndex + pageSize, totalCount);
            for (int i = startIndex; i < endIndex; i++) {
                DemoData demoData = new DemoData();
                demoData.setId(i);
                demoData.setName("name" + i);
                data.add(demoData);
            }
            return data;
        });*/

        // 定义数据写入器
       /* DataWriter<DemoData> dataWriter = new ExcelDataWriter<DemoData>(excelWriter, writeSheet);

        // 定义导出器
        ExcelExport<DemoData> export = new ExcelExport<>(pageQuery, dataWriter);

        // 启动多线程分页导出
        export.export(4);

        // 关闭ExcelWriter对象，释放资源
        excelWriter.finish();*/


    }
}
